package com.example.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.book.entity.Book;
import com.example.book.entity.Finish;
import com.example.book.entity.Recommend;
import com.example.book.mapper.FinishMapper;
import com.example.book.mapper.RecommendMapper;
import com.example.book.service.IBookService;
import com.example.book.service.IFinishService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.book.service.IRecommendService;
import com.example.common.dtos.ResponseResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class FinishServiceImpl extends ServiceImpl<FinishMapper, Finish> implements IFinishService {

    @Autowired
    private FinishMapper finishMapper;
    @Autowired
    private IBookService bookService;
    /**
     * 查询图书类型
     *
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public ResponseResult<Page> pageInfo(Integer page, Integer pageSize, String name) {
        Page<Finish> page1 = new Page(page, pageSize);
        LambdaQueryWrapper<Finish> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Finish::getName, name);
        Page<Finish> FinishPage = this.page(page1, queryWrapper);
        return ResponseResult.okResult(FinishPage);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @Override
    public ResponseResult deleteFinish(int[] ids) {
        for (int id : ids) {
            this.removeById(id);
        }
        return ResponseResult.okResult("图书推荐删除成功");
    }

    /**
     * 推荐榜图书详细查询
     *
     * @return
     */
    @Override
    public ResponseResult finishAll() {
        Long[] bookIds = finishMapper.selectAllBookIds();
        return ResponseResult.okResult(bookService.bookIdList(bookIds));
        //.bookIdList(bookIds)
    }
}
